library("FRESA.CAD")
library(readxl)
library(igraph)
library(umap)
library(tsne)
library(entropy)
op <- par(no.readonly = TRUE)
pander::panderOptions('digits', 3)
pander::panderOptions('table.split.table', 400)
pander::panderOptions('keep.trailing.zeros',TRUE)
Data Source https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6960825/
Mohino-Herranz I, Gil-Pita R, Rosa-Zurera M, Seoane F. Activity Recognition Using Wearable Physiological Measurements: Selection of Features from a Comprehensive Literature Study. Sensors (Basel). 2019 Dec 13;19(24):0. doi: 10.3390/s19245524. PMID: 31847261; PMCID: PMC6960825.
Activitydata <- read.csv("~/GitHub/LatentBiomarkers/Data/ActivityData/data.txt", header=FALSE, stringsAsFactors=TRUE)
featNames <- read.table("~/GitHub/LatentBiomarkers/Data/ActivityData/Featurelabels.txt", quote="\"", comment.char="")
featNames <- as.character(t(featNames))
featNames <- str_replace_all(featNames,"\\(abs\\)","_A_")
featNames[duplicated(featNames)] <- paste(featNames[duplicated(featNames)],"D",sep="_")
rep_ID <- numeric(nrow(Activitydata))
ctr <- 1
for (ind in c(1:(nrow(Activitydata)-1)))
{
rep_ID[ind] <- ctr
if (Activitydata$V1[ind] != Activitydata$V1[ind+1]) ctr <- 0;
ctr <- ctr + 1
}
rownames(Activitydata) <- paste(Activitydata$V1,rep_ID,sep="_")
colnames(Activitydata) <- c("ID",featNames,"class")
Activitydata$rep <- rep_ID
tb <- table(Activitydata$class)
classes <- c("Neu","Emo","Men","Phy")
names(classes) <- names(tb)
Activitydata$class <- classes[as.character(Activitydata$class)]
table(Activitydata$class)
#>
#> Emo Men Neu Phy
#> 1120 1120 1120 1120
ID_class <- paste(Activitydata$ID,Activitydata$class)
IDCLASS <- unique(ID_class)
theclass <- Activitydata$class[!duplicated(ID_class)]
theIDs <- Activitydata$ID[!duplicated(ID_class)]
ActivitydataAvg <- NULL
for (id in IDCLASS)
{
ActivitydataAvg <- rbind(ActivitydataAvg,apply(Activitydata[ID_class==id,featNames],2,mean))
}
colnames(ActivitydataAvg) <- featNames
rownames(ActivitydataAvg) <- IDCLASS
ActivitydataAvg <- as.data.frame(ActivitydataAvg)
ActivitydataAvg$class <- theclass
ActivitydataAvg$ID <- theIDs
table(ActivitydataAvg$class)
#>
#> Emo Men Neu Phy
#> 40 40 40 40
ActivitydataAvg <- subset(ActivitydataAvg, class=="Men" | class=="Emo")
ActivitydataAvg$class <- 1*(ActivitydataAvg$class == "Men")
table(ActivitydataAvg$class)
#>
#> 0 1
#> 40 40
studyName <- "Activity"
dataframe <- ActivitydataAvg
outcome <- "class"
TopVariables <- 10
thro <- 0.80
cexheat = 0.15
Some libraries
library(psych)
library(whitening)
library("vioplot")
library("rpart")
pander::pander(c(rows=nrow(dataframe),col=ncol(dataframe)-1))
| rows | col |
|---|---|
| 80 | 534 |
pander::pander(table(dataframe[,outcome]))
| 0 | 1 |
|---|---|
| 40 | 40 |
varlist <- colnames(dataframe)
varlist <- varlist[varlist != outcome]
largeSet <- length(varlist) > 1500
Scaling and removing near zero variance columns and highly co-linear(r>0.99999) columns
### Some global cleaning
sdiszero <- apply(dataframe,2,sd) > 1.0e-16
dataframe <- dataframe[,sdiszero]
varlist <- colnames(dataframe)[colnames(dataframe) != outcome]
tokeep <- c(as.character(correlated_Remove(dataframe,varlist,thr=0.99999)),outcome)
dataframe <- dataframe[,tokeep]
varlist <- colnames(dataframe)
varlist <- varlist[varlist != outcome]
iscontinous <- sapply(apply(dataframe,2,unique),length) >= 5 ## Only variables with enough samples
dataframeScaled <- FRESAScale(dataframe,method="OrderLogit")$scaledData
numsub <- nrow(dataframe)
if (numsub > 1000) numsub <- 1000
if (!largeSet)
{
hm <- heatMaps(data=dataframeScaled[1:numsub,],
Outcome=outcome,
Scale=TRUE,
hCluster = "row",
xlab="Feature",
ylab="Sample",
srtCol=45,
srtRow=45,
cexCol=cexheat,
cexRow=cexheat
)
par(op)
}
The heat map of the data
if (!largeSet)
{
par(cex=0.6,cex.main=0.85,cex.axis=0.7)
#cormat <- Rfast::cora(as.matrix(dataframe[,varlist]),large=TRUE)
cormat <- cor(dataframe[,varlist],method="pearson")
cormat[is.na(cormat)] <- 0
gplots::heatmap.2(abs(cormat),
trace = "none",
# scale = "row",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "Original Correlation",
cexRow = cexheat,
cexCol = cexheat,
srtCol=45,
srtRow=45,
key.title=NA,
key.xlab="|Pearson Correlation|",
xlab="Feature", ylab="Feature")
diag(cormat) <- 0
print(max(abs(cormat)))
}
[1]
1
DEdataframe <- IDeA(dataframe,verbose=TRUE,thr=thro)
#>
#> Included: 361 , Uni p: 0.0006887052 , Outcome-Driven Size: 0 , Base Size: 50 , Rcrit: 0.3517299
#>
#>
1 <R=1.000,thr=0.900,N= 304>, Top: 26( 1 )[ 1 : 26 Fa= 26 : 0.900 ]( 26 , 218 , 0 ),<|>Tot Used: 244 , Added: 218 , Zero Std: 0 , Max Cor: 1.000
#>
2 <R=1.000,thr=0.900,N= 304>, Top: 38( 2 )[ 1 : 38 Fa= 58 : 0.900 ]( 38 , 162 , 26 ),<|>Tot Used: 282 , Added: 162 , Zero Std: 0 , Max Cor: 1.000
#>
3 <R=1.000,thr=0.900,N= 304>, Top: 34( 1 )[ 1 : 34 Fa= 91 : 0.900 ]( 34 , 97 , 58 ),<|>Tot Used: 296 , Added: 97 , Zero Std: 0 , Max Cor: 1.000
#>
4 <R=1.000,thr=0.900,N= 304>, Top: 19( 1 )[ 1 : 19 Fa= 108 : 0.900 ]( 19 , 40 , 91 ),<|>Tot Used: 298 , Added: 40 , Zero Std: 0 , Max Cor: 1.000
#>
5 <R=1.000,thr=0.900,N= 304>, Top: 8( 4 )[ 1 : 8 Fa= 115 : 0.900 ]( 8 , 15 , 108 ),<|>Tot Used: 298 , Added: 15 , Zero Std: 0 , Max Cor: 1.000
#>
6 <R=1.000,thr=0.900,N= 304>, Top: 2( 2 )[ 1 : 2 Fa= 116 : 0.900 ]( 2 , 6 , 115 ),<|>Tot Used: 298 , Added: 6 , Zero Std: 0 , Max Cor: 1.000
#>
7 <R=1.000,thr=0.900,N= 304>, Top: 1( 4 )[ 1 : 1 Fa= 116 : 0.900 ]( 1 , 4 , 116 ),<|>Tot Used: 298 , Added: 4 , Zero Std: 0 , Max Cor: 1.000
#>
8 <R=1.000,thr=0.900,N= 304>, Top: 1( 4 )[ 1 : 1 Fa= 116 : 0.900 ]( 1 , 4 , 116 ),<|>Tot Used: 298 , Added: 4 , Zero Std: 0 , Max Cor: 1.000
#>
9 <R=1.000,thr=0.900,N= 304>, Top: 1( 4 )[ 1 : 1 Fa= 116 : 0.900 ]( 1 , 4 , 116 ),<|>Tot Used: 298 , Added: 4 , Zero Std: 0 , Max Cor: 1.000
#>
10 <R=1.000,thr=0.900,N= 304>, Top: 1( 3 )[ 1 : 1 Fa= 117 : 0.900 ]( 1 , 3 , 116 ),<|>Tot Used: 298 , Added: 3 , Zero Std: 0 , Max Cor: 0.899
#>
11 <R=0.899,thr=0.800,N= 165>, Top: 50( 6 )=( 1 )[ 2 : 50 Fa= 134 : 0.827 ]( 47 , 75 , 117 ),<|>Tot Used: 321 , Added: 75 , Zero Std: 0 , Max Cor: 0.995
#>
12 <R=0.995,thr=0.900,N= 22>, Top: 10( 2 )[ 1 : 10 Fa= 136 : 0.900 ]( 10 , 12 , 134 ),<|>Tot Used: 322 , Added: 12 , Zero Std: 0 , Max Cor: 0.995
#>
13 <R=0.995,thr=0.900,N= 22>, Top: 4( 1 )[ 1 : 4 Fa= 137 : 0.900 ]( 4 , 4 , 136 ),<|>Tot Used: 322 , Added: 4 , Zero Std: 0 , Max Cor: 0.922
#>
14 <R=0.922,thr=0.900,N= 22>, Top: 1( 1 )[ 1 : 1 Fa= 138 : 0.900 ]( 1 , 1 , 137 ),<|>Tot Used: 322 , Added: 1 , Zero Std: 0 , Max Cor: 0.892
#>
15 <R=0.892,thr=0.800,N= 63>, Top: 22( 2 )[ 1 : 22 Fa= 145 : 0.800 ]( 21 , 29 , 138 ),<|>Tot Used: 326 , Added: 29 , Zero Std: 0 , Max Cor: 0.929
#>
16 <R=0.929,thr=0.900,N= 4>, Top: 2( 1 )[ 1 : 2 Fa= 145 : 0.900 ]( 2 , 2 , 145 ),<|>Tot Used: 326 , Added: 2 , Zero Std: 0 , Max Cor: 0.986
#>
17 <R=0.986,thr=0.900,N= 4>, Top: 2( 1 )[ 1 : 2 Fa= 145 : 0.900 ]( 2 , 2 , 145 ),<|>Tot Used: 326 , Added: 2 , Zero Std: 0 , Max Cor: 0.966
#>
18 <R=0.966,thr=0.900,N= 4>, Top: 1( 1 )[ 1 : 1 Fa= 146 : 0.900 ]( 1 , 1 , 145 ),<|>Tot Used: 326 , Added: 1 , Zero Std: 0 , Max Cor: 0.893
#>
19 <R=0.893,thr=0.800,N= 17>, Top: 8( 1 )[ 1 : 8 Fa= 147 : 0.800 ]( 8 , 9 , 146 ),<|>Tot Used: 328 , Added: 9 , Zero Std: 0 , Max Cor: 0.860
#>
20 <R=0.860,thr=0.800,N= 17>, Top: 2( 1 )[ 1 : 2 Fa= 148 : 0.800 ]( 2 , 2 , 147 ),<|>Tot Used: 329 , Added: 2 , Zero Std: 0 , Max Cor: 0.798
#>
21 <R=0.798,thr=0.800,N= 17>
#>
[ 21 ], 0.8965018 Decor Dimension: 329 Nused: 329 . Cor to Base: 242 , ABase: 21 , Outcome Base: 0
#>
varlistc <- colnames(DEdataframe)[colnames(DEdataframe) != outcome]
pander::pander(sum(apply(dataframe[,varlist],2,var)))
2.43e+21
pander::pander(sum(apply(DEdataframe[,varlistc],2,var)))
3.04e+14
pander::pander(entropy(discretize(unlist(dataframe[,varlist]), 256)))
0.0195
pander::pander(entropy(discretize(unlist(DEdataframe[,varlistc]), 256)))
0.0714
if (!largeSet)
{
par(cex=0.6,cex.main=0.85,cex.axis=0.7)
UPLTM <- attr(DEdataframe,"UPLTM")
gplots::heatmap.2(1.0*(abs(UPLTM)>0),
trace = "none",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "Decorrelation matrix",
cexRow = cexheat,
cexCol = cexheat,
srtCol=45,
srtRow=45,
key.title=NA,
key.xlab="|Beta|>0",
xlab="Output Feature", ylab="Input Feature")
par(op)
}
if (!largeSet)
{
cormat <- cor(DEdataframe[,varlistc],method="pearson")
cormat[is.na(cormat)] <- 0
gplots::heatmap.2(abs(cormat),
trace = "none",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "Correlation after IDeA",
cexRow = cexheat,
cexCol = cexheat,
srtCol=45,
srtRow=45,
key.title=NA,
key.xlab="|Pearson Correlation|",
xlab="Feature", ylab="Feature")
par(op)
diag(cormat) <- 0
print(max(abs(cormat)))
}
[1]
1
if (nrow(dataframe) < 1000)
{
classes <- unique(dataframe[1:numsub,outcome])
raincolors <- rainbow(length(classes))
names(raincolors) <- classes
datasetframe.umap = umap(scale(dataframe[1:numsub,varlist]),n_components=2)
plot(datasetframe.umap$layout,xlab="U1",ylab="U2",main="UMAP: Original",t='n')
text(datasetframe.umap$layout,labels=dataframe[1:numsub,outcome],col=raincolors[dataframe[1:numsub,outcome]+1])
}
if (nrow(dataframe) < 1000)
{
datasetframe.umap = umap(scale(DEdataframe[1:numsub,varlistc]),n_components=2)
plot(datasetframe.umap$layout,xlab="U1",ylab="U2",main="UMAP: After IDeA",t='n')
text(datasetframe.umap$layout,labels=DEdataframe[1:numsub,outcome],col=raincolors[DEdataframe[1:numsub,outcome]+1])
}
univarRAW <- uniRankVar(varlist,
paste(outcome,"~1"),
outcome,
dataframe,
rankingTest="AUC")
100 : ECG_p_LF_mean 200 : IT_CCV_LF 300 : EDA_Original_mad_D
univarDe <- uniRankVar(varlistc,
paste(outcome,"~1"),
outcome,
DEdataframe,
rankingTest="AUC",
)
100 : La_ECG_p_LF_mean 200 : La_IT_CCV_LF 300 : La_EDA_Original_mad_D
univariate_columns <- c("caseMean","caseStd","controlMean","controlStd","controlKSP","ROCAUC")
##top variables
topvar <- c(1:length(varlist)) <= TopVariables
tableRaw <- univarRAW$orderframe[topvar,univariate_columns]
pander::pander(tableRaw)
| caseMean | caseStd | controlMean | controlStd | controlKSP | ROCAUC | |
|---|---|---|---|---|---|---|
| ECG_hrv_prctile75 | -2.719 | 8.9741 | -5.8408 | 10.9387 | 0.00378 | 0.731 |
| ECG_hrv_geomean_A_ | 10.370 | 8.0477 | 13.8743 | 7.8682 | 0.00822 | 0.727 |
| IT_LF_baseline_D | 43.569 | 25.1600 | 26.4345 | 15.3449 | 0.61672 | 0.721 |
| IT_p_Total_baseline | 51.974 | 29.4230 | 31.5389 | 17.9800 | 0.71076 | 0.721 |
| IT_VLF_baseline | 57.578 | 32.3488 | 34.9418 | 19.7865 | 0.75500 | 0.720 |
| ECG_hrv_prctile25 | -12.471 | 7.7963 | -16.6349 | 6.7770 | 0.20654 | 0.719 |
| IT_PSD_baseline | 0.059 | 0.0376 | 0.0358 | 0.0228 | 0.21000 | 0.715 |
| ECG_hrv_mean | -7.294 | 5.4920 | -11.0369 | 6.0390 | 0.33833 | 0.714 |
| IT_HF_baseline | 3.308 | 3.5341 | 2.0033 | 2.1158 | 0.00564 | 0.713 |
| ECG_hrv_trimmean25 | -7.619 | 6.1613 | -11.3761 | 6.3193 | 0.35724 | 0.711 |
topLAvar <- univarDe$orderframe$Name[str_detect(univarDe$orderframe$Name,"La_")]
topLAvar <- unique(c(univarDe$orderframe$Name[topvar],topLAvar[1:as.integer(TopVariables/2)]))
finalTable <- univarDe$orderframe[topLAvar,univariate_columns]
pander::pander(finalTable)
| caseMean | caseStd | controlMean | controlStd | controlKSP | ROCAUC | |
|---|---|---|---|---|---|---|
| La_EDA_Original_mad_D | -8.194 | 1.10e+01 | 0.1783 | 8.63e+00 | 0.01257 | 0.774 |
| La_IT_BRV_baseline | -3.930 | 2.27e+00 | -2.1142 | 1.54e+00 | 0.80056 | 0.756 |
| La_EDA_Original_baseline_D | -589.265 | 1.71e+03 | 639.0354 | 1.15e+03 | 0.01696 | 0.739 |
| La_EDA_processed_median_D | -1.853 | 3.44e+00 | 0.1873 | 1.38e+00 | 0.08119 | 0.731 |
| ECG_hrv_geomean_A_ | 10.370 | 8.05e+00 | 13.8743 | 7.87e+00 | 0.00822 | 0.727 |
| IT_PSD_baseline | 0.059 | 3.76e-02 | 0.0358 | 2.28e-02 | 0.21000 | 0.715 |
| La_EDA_Original_max_D | 158.330 | 2.77e+02 | -11.5921 | 2.11e+02 | 0.00189 | 0.715 |
| La_ECG_hrv_max | -10.885 | 6.35e+00 | -15.5103 | 7.31e+00 | 0.61760 | 0.714 |
| La_ECG_RR_window_baseline | 42.761 | 1.28e+01 | 34.8037 | 1.31e+01 | 0.55170 | 0.713 |
| ECG_hrv_trimmean25 | -7.619 | 6.16e+00 | -11.3761 | 6.32e+00 | 0.35724 | 0.711 |
dc <- getLatentCoefficients(DEdataframe)
fscores <- attr(DEdataframe,"fscore")
pander::pander(c(mean=mean(sapply(dc,length)),total=length(dc),fraction=length(dc)/(ncol(dataframe)-1)))
| mean | total | fraction |
|---|---|---|
| 3.32 | 295 | 0.808 |
theCharformulas <- attr(dc,"LatentCharFormulas")
finalTable <- rbind(finalTable,tableRaw[topvar[!(topvar %in% topLAvar)],univariate_columns])
orgnamez <- rownames(finalTable)
orgnamez <- str_remove_all(orgnamez,"La_")
finalTable$RAWAUC <- univarRAW$orderframe[orgnamez,"ROCAUC"]
finalTable$DecorFormula <- theCharformulas[rownames(finalTable)]
finalTable$fscores <- fscores[rownames(finalTable)]
Final_Columns <- c("DecorFormula","caseMean","caseStd","controlMean","controlStd","controlKSP","ROCAUC","RAWAUC","fscores")
finalTable <- finalTable[order(-finalTable$ROCAUC),]
pander::pander(finalTable[,Final_Columns])
| DecorFormula | caseMean | caseStd | controlMean | controlStd | controlKSP | ROCAUC | RAWAUC | fscores | |
|---|---|---|---|---|---|---|---|---|---|
| La_EDA_Original_mad_D | + EDA_Original_mad_D - (0.844)EDA_Filt1_std_D + (0.322)EDA_Functionals_power_Fil12harmmean_D | -8.194 | 1.10e+01 | 0.1783 | 8.63e+00 | 0.01257 | 0.774 | 0.507 | -1 |
| La_IT_BRV_baseline | - (0.588)IT_BRV_mean + IT_BRV_baseline | -3.930 | 2.27e+00 | -2.1142 | 1.54e+00 | 0.80056 | 0.756 | 0.642 | -1 |
| La_EDA_Original_baseline_D | + EDA_Original_baseline_D - (0.877)EDA_Filt1_prctile75_D | -589.265 | 1.71e+03 | 639.0354 | 1.15e+03 | 0.01696 | 0.739 | 0.504 | 0 |
| La_EDA_processed_median_D | - (1.418)EDA_processed_trimmean25_D + EDA_processed_median_D | -1.853 | 3.44e+00 | 0.1873 | 1.38e+00 | 0.08119 | 0.731 | 0.530 | -1 |
| ECG_hrv_prctile75 | NA | -2.719 | 8.97e+00 | -5.8408 | 1.09e+01 | 0.00378 | 0.731 | 0.731 | NA |
| ECG_hrv_geomean_A_ | NA | 10.370 | 8.05e+00 | 13.8743 | 7.87e+00 | 0.00822 | 0.727 | 0.727 | 2 |
| ECG_hrv_geomean_A_1 | NA | 10.370 | 8.05e+00 | 13.8743 | 7.87e+00 | 0.00822 | 0.727 | NA | NA |
| IT_LF_baseline_D | NA | 43.569 | 2.52e+01 | 26.4345 | 1.53e+01 | 0.61672 | 0.721 | 0.721 | NA |
| IT_p_Total_baseline | NA | 51.974 | 2.94e+01 | 31.5389 | 1.80e+01 | 0.71076 | 0.721 | 0.721 | NA |
| IT_VLF_baseline | NA | 57.578 | 3.23e+01 | 34.9418 | 1.98e+01 | 0.75500 | 0.720 | 0.720 | NA |
| ECG_hrv_prctile25 | NA | -12.471 | 7.80e+00 | -16.6349 | 6.78e+00 | 0.20654 | 0.719 | 0.719 | NA |
| IT_PSD_baseline | NA | 0.059 | 3.76e-02 | 0.0358 | 2.28e-02 | 0.21000 | 0.715 | 0.715 | 5 |
| La_EDA_Original_max_D | + EDA_Original_max_D - (2.983)EDA_Filt1_prctile75_D + (1.987)EDA_Filt1_geomean_A__D | 158.330 | 2.77e+02 | -11.5921 | 2.11e+02 | 0.00189 | 0.715 | 0.575 | -2 |
| IT_PSD_baseline1 | NA | 0.059 | 3.76e-02 | 0.0358 | 2.28e-02 | 0.21000 | 0.715 | NA | NA |
| La_ECG_hrv_max | + ECG_hrv_max - (17.710)ECG_CCV_LF | -10.885 | 6.35e+00 | -15.5103 | 7.31e+00 | 0.61760 | 0.714 | 0.661 | -1 |
| ECG_hrv_mean | NA | -7.294 | 5.49e+00 | -11.0369 | 6.04e+00 | 0.33833 | 0.714 | 0.714 | NA |
| La_ECG_RR_window_baseline | - (0.824)ECG_RR_window_median + ECG_RR_window_baseline | 42.761 | 1.28e+01 | 34.8037 | 1.31e+01 | 0.55170 | 0.713 | 0.522 | 0 |
| IT_HF_baseline | NA | 3.308 | 3.53e+00 | 2.0033 | 2.12e+00 | 0.00564 | 0.713 | 0.713 | NA |
| ECG_hrv_trimmean25 | NA | -7.619 | 6.16e+00 | -11.3761 | 6.32e+00 | 0.35724 | 0.711 | 0.711 | 4 |
| ECG_hrv_trimmean251 | NA | -7.619 | 6.16e+00 | -11.3761 | 6.32e+00 | 0.35724 | 0.711 | NA | NA |
featuresnames <- colnames(dataframe)[colnames(dataframe) != outcome]
pc <- prcomp(dataframe[,iscontinous],center = TRUE,scale. = TRUE) #principal components
predPCA <- predict(pc,dataframe[,iscontinous])
PCAdataframe <- as.data.frame(cbind(predPCA,dataframe[,!iscontinous]))
colnames(PCAdataframe) <- c(colnames(predPCA),colnames(dataframe)[!iscontinous])
#plot(PCAdataframe[,colnames(PCAdataframe)!=outcome],col=dataframe[,outcome],cex=0.65,cex.lab=0.5,cex.axis=0.75,cex.sub=0.5,cex.main=0.75)
#pander::pander(pc$rotation)
PCACor <- cor(PCAdataframe[,colnames(PCAdataframe) != outcome])
gplots::heatmap.2(abs(PCACor),
trace = "none",
# scale = "row",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "PCA Correlation",
cexRow = 0.5,
cexCol = 0.5,
srtCol=45,
srtRow= -45,
key.title=NA,
key.xlab="Pearson Correlation",
xlab="Feature", ylab="Feature")
EFAdataframe <- dataframeScaled
if (length(iscontinous) < 2000)
{
topred <- min(length(iscontinous),nrow(dataframeScaled),ncol(predPCA)/2)
if (topred < 2) topred <- 2
uls <- fa(dataframeScaled[,iscontinous],nfactors=topred,rotate="varimax",warnings=FALSE) # EFA analysis
predEFA <- predict(uls,dataframeScaled[,iscontinous])
EFAdataframe <- as.data.frame(cbind(predEFA,dataframeScaled[,!iscontinous]))
colnames(EFAdataframe) <- c(colnames(predEFA),colnames(dataframeScaled)[!iscontinous])
EFACor <- cor(EFAdataframe[,colnames(EFAdataframe) != outcome])
gplots::heatmap.2(abs(EFACor),
trace = "none",
# scale = "row",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "EFA Correlation",
cexRow = 0.5,
cexCol = 0.5,
srtCol=45,
srtRow= -45,
key.title=NA,
key.xlab="Pearson Correlation",
xlab="Feature", ylab="Feature")
}
par(op)
par(xpd = TRUE)
dataframe[,outcome] <- factor(dataframe[,outcome])
rawmodel <- rpart(paste(outcome,"~."),dataframe,control=rpart.control(maxdepth=3))
pr <- predict(rawmodel,dataframe,type = "class")
ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
if (length(unique(pr))>1)
{
plot(rawmodel,main="Raw",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
text(rawmodel, use.n = TRUE,cex=0.75)
ptab <- epiR::epi.tests(table(pr==0,dataframe[,outcome]==0))
}
pander::pander(table(dataframe[,outcome],pr))
| 0 | 1 | |
|---|---|---|
| 0 | 38 | 2 |
| 1 | 7 | 33 |
pander::pander(ptab$detail[c(5,3,4,6),])
| statistic | est | lower | upper | |
|---|---|---|---|---|
| 5 | diag.ac | 0.887 | 0.797 | 0.947 |
| 3 | se | 0.825 | 0.672 | 0.927 |
| 4 | sp | 0.950 | 0.831 | 0.994 |
| 6 | diag.or | 89.571 | 17.389 | 461.391 |
par(op)
par(xpd = TRUE)
DEdataframe[,outcome] <- factor(DEdataframe[,outcome])
IDeAmodel <- rpart(paste(outcome,"~."),DEdataframe,control=rpart.control(maxdepth=3))
pr <- predict(IDeAmodel,DEdataframe,type = "class")
ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
if (length(unique(pr))>1)
{
plot(IDeAmodel,main="IDeA",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
text(IDeAmodel, use.n = TRUE,cex=0.75)
ptab <- epiR::epi.tests(table(pr==0,DEdataframe[,outcome]==0))
}
pander::pander(table(DEdataframe[,outcome],pr))
| 0 | 1 | |
|---|---|---|
| 0 | 40 | 0 |
| 1 | 8 | 32 |
pander::pander(ptab$detail[c(5,3,4,6),])
| statistic | est | lower | upper | |
|---|---|---|---|---|
| 5 | diag.ac | 0.9 | 0.812 | 0.956 |
| 3 | se | 0.8 | 0.644 | 0.909 |
| 4 | sp | 1.0 | 0.912 | 1.000 |
| 6 | diag.or | Inf | NA | Inf |
par(op)
par(xpd = TRUE)
PCAdataframe[,outcome] <- factor(PCAdataframe[,outcome])
PCAmodel <- rpart(paste(outcome,"~."),PCAdataframe,control=rpart.control(maxdepth=3))
pr <- predict(PCAmodel,PCAdataframe,type = "class")
ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
if (length(unique(pr))>1)
{
plot(PCAmodel,main="PCA",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
text(PCAmodel, use.n = TRUE,cex=0.75)
ptab <- epiR::epi.tests(table(pr==0,PCAdataframe[,outcome]==0))
}
pander::pander(table(PCAdataframe[,outcome],pr))
| 0 | 1 | |
|---|---|---|
| 0 | 26 | 14 |
| 1 | 4 | 36 |
pander::pander(ptab$detail[c(5,3,4,6),])
| statistic | est | lower | upper | |
|---|---|---|---|---|
| 5 | diag.ac | 0.775 | 0.668 | 0.861 |
| 3 | se | 0.900 | 0.763 | 0.972 |
| 4 | sp | 0.650 | 0.483 | 0.794 |
| 6 | diag.or | 16.714 | 4.933 | 56.633 |
par(op)
EFAdataframe[,outcome] <- factor(EFAdataframe[,outcome])
EFAmodel <- rpart(paste(outcome,"~."),EFAdataframe,control=rpart.control(maxdepth=3))
pr <- predict(EFAmodel,EFAdataframe,type = "class")
ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
if (length(unique(pr))>1)
{
plot(EFAmodel,main="EFA",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
text(EFAmodel, use.n = TRUE,cex=0.75)
ptab <- epiR::epi.tests(table(pr==0,EFAdataframe[,outcome]==0))
}
pander::pander(table(EFAdataframe[,outcome],pr))
| 0 | 1 | |
|---|---|---|
| 0 | 29 | 11 |
| 1 | 6 | 34 |
pander::pander(ptab$detail[c(5,3,4,6),])
| statistic | est | lower | upper | |
|---|---|---|---|---|
| 5 | diag.ac | 0.787 | 0.682 | 0.871 |
| 3 | se | 0.850 | 0.702 | 0.943 |
| 4 | sp | 0.725 | 0.561 | 0.854 |
| 6 | diag.or | 14.939 | 4.917 | 45.389 |
par(op)